package com.ykefu.assign.netty;

import io.netty.channel.Channel;

import java.util.Enumeration;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author likai
 * @date 2020/4/8 15:20
 * @email likai@7moor..com
 * @desc
 */
public class AssignSessionStore {

    /**
     * channel存储器
     */
    private static final ConcurrentHashMap<String, Channel> channelStore = new ConcurrentHashMap<>();

    public static void store(String id,Channel channel){
        channelStore.put(id,channel);
    }

    public static void remove(String id){
        channelStore.remove(id);
    }

    public static String getOne(){
        Enumeration<String> keys = channelStore.keys();
        if(keys!=null){
            return keys.nextElement();
        }
        return null;
    }

    public static Channel getChannel(String id){
        return channelStore.get(id);
    }


    public static int size(){
        return channelStore.size();
    }
}
